package com.leanote.berial.tingphone.client;

/**
 * Created with InetlliJ IDEA.
 * Project: com.liuhui.zhufengfm.app.client
 * user  Pinocchio
 * Date 2015/7/28
 * Email:liu594545591@126.com
 */

import java.io.UnsupportedEncodingException;

/**
 * 发现部分的API接口调用
 */
public class ClientDiscoverAPI {
    public static final String SERVER_MOBILE = "http://mobile.ximalaya.com";

    public ClientDiscoverAPI() {
    }
    ///////////////////////////

    /**
     * 获取分类菜单<br/></>
     * 调用接口是:http://mobile.ximalaya.com/m/category_tag_menu
     * 请求方法 GET<br/>
     *
     * @param type 可选值 默认是user
     * @return
     */
    public static String getCategoryTagMenu(String type) {
        String ret = null;
        String url = null;
        StringBuilder builder = new StringBuilder();
        builder.append(SERVER_MOBILE + "/m/category_tag_menu");
        if (type != null) {
            builder.append("?type=").append(type);
            builder.append("&device=android");
        }
        url=builder.toString();
        builder = null;
        byte[] data = HttpUtil.doGet(url);
        if (data != null) {
            try {
                ret = new String(data,"utf-8");
            } catch (UnsupportedEncodingException e) {
                ret = new String(data);//乱码
            }
        }
        return ret;
    }

    /**
     * 获取发现部界面的Tab的定义<br/>
     * 调用接口:http://mobile.ximalaya.com/mobile/discovery/v1/tabs?device=android
     * @return
     */
    public static String getDiscoverTabs(){
        String ret = null;
        //RESTful
        String url = SERVER_MOBILE+"/mobile/discovery/v1/tabs?device=android";
        byte[] bytes = HttpUtil.doGet(url);
        if (bytes != null) {
            try {
                ret = new String(bytes,"utf-8");
            } catch (UnsupportedEncodingException e) {
                ret = new String(bytes);
            }
        }
        return ret;
    }

    /**
     * 获取发现的分类 <br/>
     * 调用的接口 <br/>
     * http://mobile.ximalaya.com/mobile/discovery/v1/categories?device=android&picVersion=10&scale=2
     * @return
     */
    public static String getDiscoverCategories() {
        String ret = null;
        String url = SERVER_MOBILE+"/mobile/discovery/v1/categories"
                +"?device=android"
                +"&picVersion=10"
                +"&scale=2";
        byte[] bytes = HttpUtil.doGet(url);
        if (bytes != null) {
            try {
                ret = new String(bytes,"utf-8");
            } catch (UnsupportedEncodingException e) {
                ret = new String(bytes);
            }
        }
        return ret;
    }
}
